//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

//====================================================
// Created     : 2004-1-4
// Author      : Fan Dian
// Description : Some test functions for kernel thread 0
//====================================================

#include <core.h>
#include <../core/inc/init.h>

//====================================================
// Description  : Test the status of kernel thread 0
// Parameters   : None
// Return       : None
//====================================================
inline void TestThread0()
{
    // Get the object of kernel thread 0
    Thread* pthread0 = GetThread0();

    // print the member variables of the object
    kprintf("Thread0:\n");
    kprintf("    m_uState = %d\n", pthread0->m_uState);
    kprintf("    m_bNeedReschedule = %s\n", \
        pthread0->m_bNeedReschedule ? "true" : "false");
    kprintf("    m_pOwner = %s\n", \
        pthread0->m_pOwner ? "not null" : "null");

    // print the infomation about the stack of this thread
    kprintf("    The size of data in stack is %ld bytes:\n        ESP | ", \
        (uint32_t)pthread0->m_vaKernelStack \
        - (uint32_t)pthread0->m_vaKernelStackPtr);
    for (uint_t punData = (uint_t)pthread0->m_vaKernelStackPtr;
        punData < (uint_t)pthread0->m_vaKernelStack;
        punData++) {
        byte *pbData = (byte *)punData;
        kprintf("%x%x ", (*pbData) >> 4, (*pbData) & 0x0F);
    }
    kprintf("| EBP\n");

    // print the infomation about the kernel thread scheduling
    bool_t bLink = TRUE;
    /* if ((uint32_t)&(pthread0->m_nodeRunning) \
        != (uint32_t)(pthread0->m_nodeRunning.Next()))
        bLink = FALSE;
    if ((uint32_t)&(pthread0->m_nodeRunning) \
        != (uint32_t)(pthread0->m_nodeRunning.Prev()))
        bLink = FALSE;
    if ((uint32_t)pthread0 != (uint32_t)(pthread0->Prev()))
        bLink = FALSE;
    if ((uint32_t)pthread0 != (uint32_t)(pthread0->Next()))
        bLink = FALSE;*/
    kprintf("kernel thread scheduling is %s\n", bLink ? "ok" : "bad");
}
